import storage from '../util/storage.js'//引入已封装好的storage

function axios(data){
	const { method, url, params } = data;
	const baseUrl = 'http://123.57.7.108:2048/emall';
	var token ;
	var tokenHead;
	storage.getStorage('token')
	.then(res =>{
		token = res.data;
		return storage.getStorage('tokenHead')
	})
	.then(res =>{
		tokenHead = res.data;
		return new Promise((reslove,reject) =>{
			uni.request({
				header:{
					'Authorization':tokenHead+' '+token
				},
				method:method,
				url: baseUrl + url ,
				data:params,
				success:res =>{
					if(res.data.code==200){
						reslove(res);
					}else{
						reject('数据请求失败！');
					}
				},
				fail:error =>{
					reject(error);
				}
			})
		})
	})
}

export default axios